<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="spring" uri="/WEB-INF/tlds/spring.tld"%>
<%@ taglib prefix="c" uri="/WEB-INF/tlds/c.tld"%>
<c:set var="BasePath" value="${pageContext.request.contextPath}"></c:set>
<c:set var="Plugins" value="${pageContext.request.contextPath}/res/plugins"></c:set>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>代销结算设置</title>
<link href="${Plugins}/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
<link href="${Plugins}/ligerUI/skins/Gray/css/all.css" rel="stylesheet" type="text/css" />
<script src="${Plugins}/jquery/jquery-1.3.2.min.js"	type="text/javascript"></script>
<script src="${Plugins}/ligerUI/js/ligerui.min.js" type="text/javascript"></script>
<script src="${Plugins}/jquery-validation/jquery.validate.min.js" type="text/javascript"></script>
<script src="${Plugins}/jquery-validation/jquery.metadata.js" type="text/javascript"></script>
<script src="${Plugins}/jquery-validation/messages_cn.js" type="text/javascript"></script>
<script src="${BasePath}/res/js/common/jquery.form.js" type="text/javascript"></script>
<script type="text/javascript" src="${BasePath}/res/js/ligerCommon.js"></script>
<script src="${BasePath}/res/js/common/jquery.validate.method.js" type="text/javascript"></script>
<script src="${Plugins}/datepicker/WdatePicker.js" type="text/javascript"></script>
<style type="text/css">
    body{ font-size:14px;}
    .l-table-edit {}
    .l-table-edit-td{ padding:4px;}
    .l-button-submit,.l-button-test{width:80px; float:left; margin-left:10px; padding-bottom:2px;}
    .l-verify-tip{ left:230px; top:120px;}
    .p-tab .s-lab{font-size:14px;font-family:"微软雅黑",​"宋体",​Arial,​sans-serif;}
	input.l-textarea{width:170px;height:20px;font-size:14px;}
	 .navbar {
		height: 20px;
		border-bottom: #E6E6E6 solid 1px;
		line-height: 20px;
		font-size: 12px;
	}
</style>
</head>
<body style="padding:10px">
<div class="navbar">
		<span>您当前的位置：</span>
		基本信息管理 &gt; 仓库管理 &gt;
		 <c:if test="${empty wharehouse }">
		 新增仓库
		 </c:if>
		  <c:if test="${not empty wharehouse }">
		  修改仓库
		 </c:if>
		
		
</div>
<form name="form1" method="post" action="editToWhareHouse.do" id="form1">
<br>
<table style="height: 60%;width: 100%; font-size: 12px; " cellspacing="1" cellpadding="1">
	<tr  <c:if test="${not empty wharehouse }">style="display: none;" </c:if>>
		<td>
			<span style="color: red;">*</span>仓库编码 :&nbsp;&nbsp;<input class="l-textarea" value="${wharehouse.whNo }" maxlength="10"  id="whNo" <c:if test="${not empty wharehouse.id }">readonly="readonly"</c:if> name="whNo"  type="text" />
		</td>
	</tr>
	<tr>
		<td><span style="color: red;">*</span>仓库名称 :&nbsp;&nbsp;<input  value="${wharehouse.whName }"  maxlength="15" class="l-textarea" id="whName" name="whName" type="text" /></td>
	</tr>
	<tr>
		<td> <span style="color: red;">*</span>手机号码 :&nbsp;&nbsp;<input value="${wharehouse.whPhone }" class="l-textarea" maxlength="11"  id="whPhone" name="whPhone" type="text" /></td>
	</tr>
	<tr>
		<td><span style="color: red;">*</span>　联系人 :&nbsp;&nbsp;<input value="${wharehouse.whUser }" maxlength="10" class="l-textarea"  id="whUser" name="whUser" type="text" /></td>
	</tr>
	<tr>
		<td><span style="color: red;">*</span>仓库地址 :&nbsp;&nbsp;<input value="${wharehouse.whAdderss }" maxlength="30" class="l-textarea"  id="whAdderss" name="whAdderss" type="text" /></td>
	</tr>
	<tr>
		<td><span style="color: red;">*</span>库存类型 :&nbsp;&nbsp;
			<input value="1" <c:if test="${wharehouse.whType eq null or wharehouse.whType == 1}">checked="checked"</c:if> name="whType" type="radio" />实库&nbsp;
			<input value="2" <c:if test="${wharehouse.whType == 2}">checked="checked"</c:if> name="whType" type="radio" />虚库
		</td>
	</tr>
</table>
<c:if test="${not empty wharehouse }">
	<input value="${wharehouse.deleteFlag }" id="deleteFlag" name="deleteFlag" type="hidden" />
	<input value="${wharehouse.id }"  id="id" name="id" type="hidden" />
</c:if>
<input type="submit" value="保存" id="Button1" class="l-button l-button-submit" /> 
<input type="button" value="取消" name="tests"  id="tests" onclick="javascript:closeList()" class="l-button l-button-test" />
</form>
<div style="display:none">
<!--  数据统计代码 --></div>

<script type="text/javascript">

function checkForm(){
	var inputs = $("table input");
	for(var i=0;i<inputs.length;i++){
		if(inputs[i].value==''){
			window.parent.$.ligerDialog.error("字段不能为空");
			return false;
		}
	}
	if($("#whNo").val().match(/[\u4E00-\u9FA5]/gi)){
		window.parent.$.ligerDialog.error("仓库编码不允许输入汉字");
		return false;
	}
	if(!$("#whNo").val().match(/^[0-9a-zA-Z]{1,20}$/gi)){
		window.parent.$.ligerDialog.error("仓库编码只允许输入英文,数字");
		return false;
	}	
	var myreg = /^(((13[0-9]{1})|159|153|(14[0-9]{1})|(17[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
	if(myreg.test($("#whPhone").val())){
	}else{
		window.parent.$.ligerDialog.error("请输入正确的手机号码");
		return false;
	}
		
	
	var flag = false;
	var id = $("#id").val();
	var whNo = $("#whNo").val();
	var whName = $("#whName").val();
	 $.ajax({
		   type: "POST",
		   url: "../ajaxToWhareNo.do",
		   data: "whNo="+whNo+"&id="+id+"&whName="+whName,
		   async: false,
		   success: function(msg){
		    if(msg == 'success'){
		    	flag = true;
		    }else if(msg == 'whNoError'){
		    	window.parent.$.ligerDialog.error("该仓库编码已存在");
		    }else{
		    	window.parent.$.ligerDialog.error("该仓库名称已存在");
		    }
		   }
		});  
	return flag;
}


var pageType = ${not empty wharehouse } ? '修改' : '增加';
$(function ()
		{
			//validate
		    $.metadata.setType("attr", "validate");
		    var v = $("form").validate({
		    
		        submitHandler:function()
		        {
		        	if(checkForm()){		            
		            var options = {
		            		type: 'POST',
		            		success: function(data){
		            			if(data=="success") {
		            				var s=window.parent.$.ligerDialog.success("仓库信息"+pageType+"成功","提示",function () {
		            					parent.window.location.href = parent.window.location.href ;
		            	        		});
		            	        		$(s.dialog.winbtns).remove();
		            	        } else {
		            	        		  window.parent.$.ligerDialog.error(data);
		            	        }
		            	     }	
		            	}, $form1 = $("#form1");
		           $form1.ajaxSubmit(options);
		             return false;
		        }
		    }
		    });
		}); 
		
		

		
		
// 取消
function closeList(){
	parent.window.location.href = parent.window.location.href ;
}
</script>
</body>
</html>